package com.pb.service.boot;

import com.pb.service.boot.config.MyXssCleaner;
import net.dreamlu.mica.xss.core.XssCleaner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.client.RestTemplate;

@EnableTransactionManagement
@SpringBootApplication
@ServletComponentScan
@ComponentScan({"com.pb.**"})
@EnableScheduling
public class BootApplication extends SpringBootServletInitializer implements WebApplicationInitializer {

    /**
     * 项目打成war包使用外置tomcat
     * @param builder
     * @return
     */
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(BootApplication.class);
    }

    /**
     * 注册Bean
     * @returm
     */
    @Bean
    public XssCleaner xssCleaner() {
        return new MyXssCleaner();
    }

    /**
     * 用于访问 Rest 服务
     * @return
     */
    @Bean
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

    public static void main(String[] args) {
        try {
            SpringApplication.run(BootApplication.class, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
